<?php
class ScheduleTypesController extends AppController {

	var $name = 'ScheduleTypes';

	function index() {
		$this->ScheduleType->recursive = 0;
		$this->set('scheduleTypes', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid schedule type', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('scheduleType', $this->ScheduleType->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->ScheduleType->create();
			if ($this->ScheduleType->save($this->data)) {
				$this->Session->setFlash(__('The schedule type has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The schedule type could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid schedule type', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->ScheduleType->save($this->data)) {
				$this->Session->setFlash(__('The schedule type has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The schedule type could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->ScheduleType->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for schedule type', true));
			$this->redirect(array('action'=>'index'));
		}
		if($id == '1' || $id == '2' || $id == '3'){
			$this->Session->setFlash(__('Đây là những nhóm làm việc chính của hệ thống, Không thể xóa được', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->ScheduleType->delete($id)) {
			$this->Session->setFlash(__('Schedule type deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Schedule type was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>